package cn.wolfcode.web.util;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.domain.Permission;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

public class SessionUtil {
    public static final String USER = "USER";
    public static final String PERMISSION = "PERMISSION";

    public static HttpSession getSession(){
        ServletRequestAttributes attrs =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attrs.getRequest().getSession();
    }

    public static void setAtt(String name, Object value){
        getSession().setAttribute(name, value);
    }

    public static Employee getAtt(String name){
        return (Employee)getSession().getAttribute(name);
    }

    public static List<Permission> getAttr(String name){
        return (List<Permission>) getSession().getAttribute(name);
    }
}
